home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
modules
/
trackers
/
wikipedia.js
< prev
Wrap
Text File
|
2009-10-19
|
2KB
|
64 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* wikipedia.js
* Responsible for tracking wikipedia articles
*/
var EXPORTED_SYMBOLS = ["wikipedia"];
var wikipedia = {
name: "Wikipedia",
name_plural: "Wikipedia Entries",
color: "#333",
isInternal: true,
preview: function(doc, node, data){
if(data.preview){
var result = this.json.decode(data.preview);
var len = result.length;
var box = doc.createElement('vbox');
box.className = "wikipediabox";
if(len){
for(var x = 0; x < len; x++){
var item = result[x];
var desc = doc.createElement("description");
desc.className = "wikipedia";
desc.appendChild(doc.createTextNode(item));
box.appendChild(desc);
}
}
node.appendChild(box);
}
},
onLoadTracks: function(url, doc){
var result = [];
if(doc && this.pattern.exec(url)){
var name = doc.getElementById("firstHeading").textContent;
var data = [];
var div = doc.getElementById("bodyContent");
if(div){
var len = div.childNodes.length;
for(var x= 0; x < len;x++){
var item = div.childNodes[x];
if(item.tagName == 'P'){
data.push(item.textContent);
} else if(item.id == 'toc'){
break;
}
}
result.push(
{
type: "wikipedia",
title: name,
preview: this.json.encode(data)
}
);
}
}
return result;
},
json: Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON),
pattern: /^http(s*):\/\/(.*).wikipedia.org\/wiki\//
};